package com.nyist.thread;

/**
 * 1.
 *
 * @ClassName NyistThreadUtils
 * @Description
 * @Author xiaoyang
 * @Date 2023/04/03/20:28
 */
public class NyistThreadUtils {

    /**
     * 获取当前cpu核心数量
     * @author yangxiaogen
     * @date 2023/4/6 11:08
     * @return java.lang.Integer
     */
    public static Integer getCoreThreadNumber() {
        return Runtime.getRuntime().availableProcessors();
    }

    /**
     * 获取线程名
     * @author yangxiaogen
     * @date 2023/4/3 20:29
     */
    public static Thread getThreadName(){
        return Thread.currentThread();
    }

    /**
     * 调用sleep,不需要try/catch
     * sleep not try/catch
     * @author yangxiaogen
     * @date 2023/4/3 20:29
     * @param timeout 休眠的毫秒数. 3000 等于 3秒
     */
    public static void sleep(long timeout){
        // 让程序等一会再结束掉, 就可以接收到回调信息了
        try {
            Thread.sleep(timeout);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage());
        }
    }

}
